<!-- 搜索和通讯录使用 --><template>
	<view class="friend">		
		<view class="initial" v-if="type === 'address'">
			<text class="text" v-if="data.initial !== '⬆'">{{data.initial}}</text>
		</view>
		
		<view class="list" v-for="(item,index) in data.list" :key="index"		 hover-class="hoverClassList" @tap="friendDetail(item)">
			<view class="iamgeCover">				<image :src="item.cover" class="options_image" 				v-if="data.initial === '⬆'"></image>
				<image v-else :src="item.avatar?item.avatar: '/static/avatar/default_avatar.png'"
				 class="image"></image>
			</view>
			<view class="right">				<text class="text" v-if="data.initial === '⬆'">{{item.title}}</text>
				<text class="text" v-else>{{item.nickname?item.nickname:item.username}}</text>
				
				<text 
				v-if="data.initial === '⬆' && item.title === '新的朋友' && friendStore.feiendApplicationTotal !== 0"
				class="tip">{{friendStore.feiendApplicationTotal}}</text>
				
				<view v-if="type === 'group'">
					<checkbox-group @change="checkRadio(item)">
						<checkbox class="checkbox" color='#f7931e' :checked="checked"/>
					</checkbox-group>
				</view>
				
			</view>
		</view>		
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import tips from '@/components/tip/tip.vue'
	import useFriend from '@/pinia/friend.js'
	
	const checked = ref(false) // 单选框是否被选中
	const checkedNum = ref(0) // 选择的数量
	
	const emit = defineEmits(['friendDetail'])
	
	const friendStore = useFriend()
	
	const count = ref(friendStore.feiendApplicationTotal)
	
	
	const props = defineProps({
		data: {
			type: Object,
			default: () => {}
		},
		type: {
			type: String,
			default: 'address'
		}
	})		const friendDetail = (item) =>{ // 点击进入好友详情页面
		emit('friendDetail',item)	}
	
	const checkRadio = (item) => { // 点击单选框 
		checked.value = !checked.value
		if(checked.value){
			checkedNum.value ++
			friendStore.checkedList.push(item)
		}else{
			checkedNum.value --
			const index = friendStore.checkedList.findIndex(f => f.user_id === item.user_id )
			if(index === -1) return
			friendStore.checkedList.splice(index,1)
		}
	}	
</script>

<style lang="less" scoped>
	.friend {
		.initial {
			padding: 5prx 0;
			background-color: #eee;

			.text {
				color: #333;
				font-size: 25rpx;
				margin-left: 20rpx;
			}
		}

		.list {
			height: 100rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			padding: 0 20rpx;
			border-bottom: 1rpx solid #eee;
			background-color: #fff;

			.iamgeCover {
				padding: 10rpx;
				.options_image{					width: 80rpx;					height: 80rpx;					border-radius: 10rpx;				}
				.image {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
				}
			}

			.right {
				flex: 1;
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: space-between;
				.text {
					color: #333;
					font-size: 30rpx;
				}
				.tip{
					width: 30rpx;
					height: 30rpx;
					text-align: center;
					line-height: 30rpx;
					font-size: 20rpx;
					color: #fff;
					border-radius: 50%;
					background-color: red;
				}
			}
		}
	}
</style>